package com.example.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.entity.supervision.UsedControlInspection;
import com.example.mapp.UsedControlInspectionMapp;
import com.example.service.UsedControlInspectionService;
import com.example.util.ResultUtil;

import ch.qos.logback.classic.Logger;

/**
 * Created by douyx on 2018/03/26.
 */
@Service
public class UsedControlInspectionServiceImpl implements UsedControlInspectionService {

	private final static Logger logger = (Logger) LoggerFactory.getLogger(UsedControlInspectionServiceImpl.class);

	@Autowired
	private UsedControlInspectionMapp usedControlInspectionMapp;

	@Override
	public Map<String, Object> add(UsedControlInspection usedControlInspection) {
		try {
			usedControlInspectionMapp.add(usedControlInspection);
			Map<String, Object> map = new HashMap<>();
			map.put("usedControlId", usedControlInspection.getId());
			return ResultUtil.returnSuccess("提交成功", map);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError("提交失败" + e.getMessage(), null);
		}
	}

	@Override
	public Map<String, Object> query(String id) {
		try {
			UsedControlInspection usedControlInspection = usedControlInspectionMapp.query(id);
			return ResultUtil.returnSuccess("提交成功", usedControlInspection);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError("提交失败" + e.getMessage(), null);
		}
	}

}
